import axios from 'axios'

const api = axios.create({
    baseURL: 'http://localhost:8080/',
    timeout: 5000,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
})

api.interceptors.request.use(
    config => {
        let token = sessionStorage.getItem('token')
        if (token){
            config.headers['Fall2023-Token'] = token
        }
        return config
    },
    error => {
        console.log(error)
        return Promise.reject(error)
    }
)

api.interceptors.response.use(
    response => {
        return response.data
    },
    error => {
        console.log(error)
        return Promise.reject(error)
    }
)

export default api